//
//  NYMineViewController.m
//  NiuWaJiaoYu
//
//  Created by MinLison on 2017/12/4.
//  Copyright © 2017年 niuwaketang. All rights reserved.
//

#import "NYMineViewController.h"
#import "NYMineForm.h"
#import "NYSettingViewController.h"

@interface NYMineViewController ()
@end

@implementation NYMineViewController

- (void)viewDidLoad
{
        self.form = [NYMineForm formDescriptorWithTitle:@"我的"];
        [super viewDidLoad];
}
- (void)initTableView
{
        [super initTableView];
        self.tableView.showsVerticalScrollIndicator = NO;
        self.tableView.showsHorizontalScrollIndicator = NO;
        self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        self.tableView.backgroundColor = UIColorForBackground;
        @weakify(self);
        [self.controllerView setActionBlock:^(NYMineViewClickType type) {
                @strongify(self);
                switch (type) {
                        case NYMineViewClickTypeCheckIn:
                        {
                                [self presentSignInVC];
                        }
                                break;
                        case NYMineViewClickTypeHeadImgClick:
                        {
                                [self pushToUpdateUserInfoLogInIfNeed];
                        }
                                break;
                        case NYMineViewClickTypeSettingClick:
                        {
                                [self pushSettingVC];
                        }
                                break;
                                
                        default:
                                break;
                }
        }];
}
- (void)presentSignInVC
{
        @weakify(self);
        [NYUserManager pushOrPresentLoginIfNeed:YES inViewController:self completion:^{
                
        } dismiss:^{
                @strongify(self);
                if (NYUserManager.isLogin)
                {
                        [self routeUrl:kNYSignInControllerURI param:nil handler:^(NSDictionary<NSString *,id> * _Nullable parameters, UIViewController<JLRRouteDefinitionTargetController> * _Nullable targetVC) {
                                @strongify(self);
                                [(STPopupController *)targetVC presentInViewController:self];
                        }];
                }
        }];
}
- (void)pushSettingVC
{
        @weakify(self);
        [NYUserManager pushOrPresentLoginIfNeed:YES inViewController:self completion:^{

        } dismiss:^{
                @strongify(self);
                if (NYUserManager.isLogin) {
                        NYSettingViewController *vc = [[NYSettingViewController alloc] init];
                        [self.navigationController pushViewController:vc animated:YES];
                }
        }];
}
- (void)pushToUpdateUserInfoLogInIfNeed
{
        [NYUserManager pushOrPresentUserInfoInViewController:self completion:nil dismiss:nil];
}


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
        if (section == 1)
        {
                return __WGHeight(15);
        }
        return CGFLOAT_MIN;
}

+ (NYViewControllerNavigationBarType)navigationBarType
{
        return NYViewControllerNavigationBarTypeClear;
}
@end
